﻿using EFCore.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SService;

namespace WMSWeb.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class SubordinateController : ControllerBase
    {
        private readonly WmssystemContext myDbContext;
        private readonly Sys_SubordinateS Sys_SubordinateS;

        public SubordinateController(WmssystemContext myDbContext, Sys_SubordinateS Sys_SubordinateS)
        {
            this.myDbContext = myDbContext;
            this.Sys_SubordinateS = Sys_SubordinateS;
        }
        /// <summary>
        /// 数据字典从表模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("FenYe")]
        public async Task<List<Sys_Subordinate>> FenYe(string type, string Label = null, bool? Status = null)
        {
            return await Sys_SubordinateS.FenYe(type, Label, Status);
        }
        /// <summary>
        /// 数据字典从表添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<int>> Add(Sys_Subordinate subAdd)
        {
            // 为实体的属性赋值
            subAdd.D_DIsDelete = true;
            subAdd.D_DCreationTime = DateTime.Now;

            // 调用服务层的方法执行添加操作
            return await Sys_SubordinateS.Add(subAdd);
        }
        /// <summary>
        /// 数据字典从表修改
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public async Task<ActionResult<int>> Update(Sys_Subordinate subUpd)
        {
            return await Sys_SubordinateS.Upd(subUpd);
        }
        /// <summary>
        /// 数据字典从表逻辑删除
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdIsDelete")]
        public async Task<ActionResult<int>> UpdIsDelete(int id, bool isDeleted)
        {
            return await Sys_SubordinateS.UpdIsDelete(id, isDeleted);
        }
    }
}
